package com.sixth.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sixth.dao.ECourseDao;
import com.sixth.entity.BottomArticle;
import com.sixth.entity.CourseVo;
import com.sixth.entity.ECourse;
import com.sixth.entity.TableResult;
import com.sixth.service.EcourService;
import com.sixth.until.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: self-tui-education
 * @description:
 * @author: C
 * @create: 2022-04-27 01:48
 **/
@Service
public class EcourServicelmpl implements EcourService {
@Autowired
 private ECourseDao eCourseDao;
    @Override
    public TableResult selectAlleduCourse(Integer currentPage, Integer pageSize,ECourse eduCourse) {
        PageHelper.startPage(currentPage,pageSize);
        Byte isDeleted = eduCourse.getIsDeleted();
        String title= eduCourse.getCourseTitle();
        System.out.println(isDeleted+title);
        List<ECourse> bottomArticles=eCourseDao.selectBottomByCondition(title,isDeleted);
        PageInfo<ECourse> pageInfo = new PageInfo<>(bottomArticles);

        return new TableResult(2000,"查询成功",pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public TableResult selectAlleduCoursee(Integer pageCurrent, Integer pageSize, ECourse eduCourse) {
        PageHelper.startPage(pageCurrent,pageSize);
        String status = eduCourse.getStatus();
        String title= eduCourse.getTitle();
        System.out.println(status+title);
        List<ECourse> bottomArticles=eCourseDao.selectBottomByConditionn(title,status);
        PageInfo<ECourse> pageInfo = new PageInfo<>(bottomArticles);

        return new TableResult(2000,"查询成功",pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public CommonResult deleteFindById(ECourse eCourse) {
         String id =eCourse.getId();
        int row =eCourseDao.deleteByPrimaryKey(id);
        if (row>0){
            return new CommonResult(2000,"删除成功","null");
        }else {
            return new CommonResult(5000,"删除失败","null");
        }
    }

    @Override
    public CommonResult addCourseDetail(CourseVo courseVo) {
        String courseId = courseVo.getCourseId();
        int i=eCourseDao.addCourseDetail(courseId);
        return new CommonResult(2000,"修改成功",null);
    }
}
